﻿@model CouponModel

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-form" wid100 lay-filter="">
                        <input asp-for="Id" type="hidden" />
                        @if (Model.Id > 0)
                        {
                            <div class="layui-form-item">
                                <div class="col-md-2">
                                    <u-label asp-for="Url" />
                                </div>
                                <div class="layui-form-mid layui-word-aux">
                                    @Model.Url
                                </div>
                            </div>
                        }
                        <div class="layui-form-item">
                            <div class="col-md-2">
                                <u-label asp-for="Title" />
                            </div>
                            <div class="layui-input-inline">
                                <u-editor asp-for="Title" />
                                <span asp-validation-for="Title"></span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="col-md-2">
                                <u-label asp-for="Value" />
                            </div>
                            <div class="layui-input-inline">
                                <u-editor asp-for="Value" />
                                <span asp-validation-for="Value"></span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="col-md-2">
                                <u-label asp-for="StartTime" />
                            </div>
                            <div class="layui-input-inline">
                                <u-editor asp-for="StartTime" />
                                <span asp-validation-for="StartTime"></span>
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline">
                                <u-editor asp-for="EndTime" />
                                <span asp-validation-for="EndTime"></span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="col-md-2">
                                <u-label asp-for="MinimumConsumption" />
                            </div>
                            <div class="layui-input-inline">
                                <u-editor asp-for="MinimumConsumption" />
                                <span asp-validation-for="MinimumConsumption"></span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="col-md-2">
                                <u-label asp-for="IsAmountLimit" />
                            </div>
                            <div class="layui-input-inline">
                                <u-bool asp-for="IsAmountLimit" />
                                <span asp-validation-for="IsAmountLimit"></span>
                            </div>
                        </div>
                        <div class="layui-form-item" id="amountShow" style="display:@(Model.IsAmountLimit?"block":"none");">
                            <div class="col-md-2">
                                <u-label asp-for="Amount" />
                            </div>
                            <div class="layui-input-inline">
                                <u-editor asp-for="Amount" />
                                <span asp-validation-for="Amount"></span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button style="display:none" id="set_system_submit_btn" class="layui-btn" lay-submit lay-filter="set_system_submit_btn">确认保存</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['index'], function () {
        var $ = layui.$
            , form = layui.form;

        form.on('switch(IsAmountLimit)', function (data) {
            if (data.elem.checked) {
                $('#amountShow').show();
            } //开关是否开启，true或者false
        }); 

        form.on('submit(set_system_submit_btn)', function (obj) {
            var index = layer.load(2, { shade: false });
          var field = obj.field; //获取提交的字段
            //layer.msg(JSON.stringify(obj.field));
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.post('@Url.Action("Edit")', field, function (rep) {
                if (rep.success == 1) {
                    layer.close(index);
                    layer.msg("保存成功,即将自动关闭", { time: 2 * 1000 }, function () {
                        var iframe_index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        console.log("当前iframe层的索引:" + iframe_index + "==window.name:" + window.name);
                        parent.layer.close(iframe_index); //再执行关闭
                        window.parent.location.reload();
                    });
                }
            });
            return false;
         });

    });

</script>